<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>导入数据</title>
</head>
<body>
<div id="importMdDataData" style="background-color:#FFFFFF;width:630px;margin:0 auto;">
        <div class="form-Container">
            <form action="${pageContext.request.contextPath}/mdData/importDataFromTxt.do"  id="importProducs" class="easyUIForm" method="post" enctype="multipart/form-data">
                <table>
                    <tr>
                        <td width="150"><label for="checkMsg">数据文件:</label></td>
                        <td colspan="3" style="line-height:20px;">
                            <input type="file" id="impFile" name="impFile" />
                        </td>
                    </tr>
                    <tr>
                        <td width="150"><label for="checkMsg">所属分类:</label></td>
                        <td colspan="3" style="line-height:20px;">
                            <input type="text" class="easyui-combotree" id="dataType" name="dataType"
	                           data-options="
	                                prompt:'请选择',
	                                width:244,
	                                height:25,
	                                panelHeight:300,
	                                url:'<%=basePath %>dictionary/getDictionaryList4Tree.do?parentUUID=20180826105403142872572',    
					        	    valueField:'dicname',
					        	    textField:'dicname'
					        	    "/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;">
                            <input type="button" value="开始导入文件" name="submitData"  />
                            <br/>
                            <span id="errorMsg" style="color:red;display: block;"></span>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;line-height: 22px">
                            *<a href="<%=basePath %>/excel/mdDataModel.txt">***点我下载模板****</a><br/>
                            *录入数据时请按照模板中的格式来整理,列之间用$$进行分隔<br/>
                            *文件必需是txt文件，否则导入会失败<br/>
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
        </div>			        
        <script type="text/javascript">
    	var baseId = "#importMdDataData ";
        $(document).ready(function () {
        	//提交表单数据
        	submitFormData();
        });
        
        //提交表单数据
        function submitFormData(){
        	//保存基本信息
        	$(baseId+" input[name='submitData']").click(function(){
     			    //弹出提示
     	            $.messager.progress({
     	            	msg:"正在为你导入数据,请稍后..."
     	            }); 
        		$(baseId+" #importProducs").form('submit',{
        			//当提交时
        			onSubmit:function(param){
        				//当提交时先验证一下表单
        				if(!$(this).form("validate")){
        					return false;
        				}
        			},
        			success:function(data){
        				var response = eval('(' + data + ')');
        				//关闭提示
                        $.messager.progress('close');
        				if(response.code=='00'){
          				  $.messager.show({
          					 title:'系统提示',
          					 msg:'导入数据成功...',
          					 timeout:2000,
          					 showType:'slide'
          				  });
          				  if(response.data!=null){
          					  $("#errorMsg").html("<br/>以下数据行数存在重复:<br/>"+response.data);
          				  }else{
          					 var tmid = window.setTimeout("$(\"#editDataFormArea\").window(\"close\")", "1000");
          				  }
          				  tableObject.datagrid("reload");
          			    }else{
          				   $.messager.alert('操作提示',response.msg,'error');
          			    }
        			}
        		});
        	})
        }
        </script>
      </div>
</body>
</html>